from Tkinter import *
import pygame.mixer
#import tkMessageBox

#
#def track_stop():
#    """docstring for track_stop"""
#    track.stop()

#def track_toggle():
#    """docstring for track_toggle"""
#    if track_playing.get() == 1:
#        track.play(loops = -1)
#    else:
#        track.stop()

def shutdown():
    """docstring for shutdown"""
    if tkMessageBox.askokcancel("R U sure?","Really want to quit?"):
        track.stop()
        app.destroy()

def change_volume(v):
    """docstring for change_volume"""
    track.set_volume(volume.get())
    #pass

#Creat tht GUI application window
app = Tk()
app.title("Head First Mix")
#app.geometry('250x100+200+100')

track_playing = 1
def track_toggle():
    """docstring for track_toggle"""
    global track_playing
    if (track_playing):
        track.play(loops = -1)
        track_playing = 0
        #print track_playing
    else:
        track.stop()
        track_playing = 1
        #print track_playing

#ID the track
sound_file = "50459_M_RED_Nephlimizer.wav"

mixer = pygame.mixer
mixer.init()
track = mixer.Sound(sound_file)
track.set_volume(0.5)

#Creat button for start and stop
#start_button = Button(app, command = track_start, text = "Start")
#start_button.pack(side = LEFT)
toggle_button = Button(app, command = track_toggle, text = "toggle")
toggle_button.pack(side = LEFT)
#
#stop_button = Button(app, command = track_stop, text = "Stop")
#stop_button.pack(side = RIGHT)

#Checkbutton(app, variable = track_playing, command = track_toggle, text = "Flip it?").pack()

#app.protocol("WM_DELETE_WINDOW", shutdown)

#SET volume
volume = DoubleVar()
volume_scale = Scale(app,
                    variable = volume,
                    from_ = 0.0,
                    to  = 1.0,
                    resolution = 0.01,
                    command = change_volume,
                    label = "Volume",
                    orient = HORIZONTAL)
# set the default volume
volume_scale.set(0.5)
volume_scale.pack(side=RIGHT)

app.mainloop()
